package com.incar.chuxing.utils.Dialogs;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.incar.chuxing.R;

/**
 * 创建自定义的dialog，主要学习其实现原理
 * Created by Michael Pi  on 2016/3/22.
 */
public class CarInsufficientDepositDialog extends Dialog {

    private Button carPayCharge;//确定按钮
    private RelativeLayout payMethodWeiXin;
    private RelativeLayout payMethodZfb;

    //确定文本和取消文本的显示内容
    private TextView tvBalance;//余额
    private TextView tvMoney;//应付金额
    private String balance;
    private String money;
    private ChargeOnClickListener chargeOnClickListener;//点击充值
    private WxOnClickListener wxOnClickListener;//点击微信
    private ZfbOnClickListener zfbOnClickListener;//点击支付宝


    public void setChargeOnClickListener(ChargeOnClickListener chargeOnClickListener) {

        this.chargeOnClickListener = chargeOnClickListener;
    }

    public void setWxOnClickListener(WxOnClickListener wxOnClickListener) {
        this.wxOnClickListener = wxOnClickListener;
    }

    public void setZfbOnClickListener(ZfbOnClickListener zfbOnClickListener) {
        this.zfbOnClickListener = zfbOnClickListener;
    }

    public CarInsufficientDepositDialog(Context context) {
        super(context, R.style.MyDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_car_insufficient_deposit);
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);

        //初始化界面控件
        initView();
        //初始化界面数据
        initData();
        //初始化界面控件的事件
        initEvent();
    }

    /**
     * 初始化界面的确定和取消监听器
     */
    private void initEvent() {
        payMethodWeiXin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (wxOnClickListener != null) {
                    wxOnClickListener.onWxClick();
                }
            }
        });

        carPayCharge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (chargeOnClickListener != null) {
                    chargeOnClickListener.onChargeClick();
                }
            }
        });

        payMethodZfb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (zfbOnClickListener != null) {
                    zfbOnClickListener.onZfbClick();
                }
            }
        });
    }

    /**
     * 初始化界面控件的显示数据
     */
    private void initData() {
        if (balance != null) {
            tvBalance.setText(balance);
        }
        if (money != null) {
            tvMoney.setText(money);
        }
    }

    /**
     * 初始化界面控件
     */
    private void initView() {
        carPayCharge = (Button) findViewById(R.id.car_pay_charge);
        payMethodWeiXin = (RelativeLayout) findViewById(R.id.pay_method_weiXin);
        payMethodZfb = (RelativeLayout) findViewById(R.id.pay_method_zfb);
        tvBalance = (TextView) findViewById(R.id.car_balance_money);
        tvMoney = (TextView) findViewById(R.id.car_pay_money);
    }

    /**
     * 余额
     *
     * @param balance
     */
    public void setBalance(String balance) {
        this.balance = "当前余额" + balance + "元";
    }

    /**
     * 应付金额
     *
     * @param money
     */
    public void setPayMoney(String money) {
        this.money = "应付金额" + money + "元";
    }


    public interface WxOnClickListener {
        public void onWxClick();
    }

    public interface ChargeOnClickListener {
        public void onChargeClick();
    }

    public interface ZfbOnClickListener {
        public void onZfbClick();
    }
}
